/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include "RecklessBrain.h"
#include "EntityManager.h"
#include "IEntity.h"

RecklessBrain::RecklessBrain(void)
{
}

RecklessBrain::~RecklessBrain(void)
{

}

/** Move towards an enemy */
void RecklessBrain::Think(IEntity* entPtr)
{
    //the entity we will manipulate
    IEntity* enemy = EntityManager::GetInstance()->Find( entPtr->m_attributes.GetStr("ai_enemy" ) );
    if ( !enemy ) return;

	AI_Data &data = m_dataTable[entPtr];
    Vector2f enemyPosition = enemy->m_physObject.GetPosition();
    Vector2f entityPosition = entPtr->m_physObject.GetPosition();

	float distance = entityPosition.Distance( enemyPosition );
	if( EnemyInView( entPtr->GetFace(), enemyPosition, entityPosition ) && distance < 256.0f )
		data.awareOfPlayer = true;

	if(distance < data.minRange || distance > data.followDistance || !data.awareOfPlayer)
	{
		entPtr->m_actions = 0;
		if(data.patrol.size() > 0 && !data.awareOfPlayer)
			ContinuePatrol(entPtr);
		return;
	}

    //if ( entPtr->GetState() == ENT_STATES[ HIT ] || data.inRoute )
    //{
    //    data.inRoute = true;
    //    FindCover( entPtr, enemy );
    //}
    //else
    {
        CheckStuck(entPtr, enemyPosition );
        GoToEntity(entPtr, enemy );
    }
	
}
